p<- 10
n <- 1000000
X1 <- matrix(runif(n*p,min=-1,max=1),ncol=p) # uniform points in [-1,1]^p
normX1 <- apply(X1*X1,1,sum)
X <- X1[normX1<=1,] # uniform points in B(0,1) in dimension p
normX <- normX1[normX1<=1]
dim(X)[1]
## [1] 2475
dim(X)[1]/n
## [1] 0.002475
sum(normX<=.5)
## [1] 68
plot(X[,1:2],pch=20-(normX<=.5),col=2+6*(normX>.5))
MDS:
library(smacof)
## Loading required package: plotrix
## Loading required package: colorspace
## Loading required package: e1071
##
## Attaching package: 'smacof'
## The following object is masked from 'package:base':
##
## transform
dX <- dist(X)
mdsX <- mds(dX,ndim=2)
plot(mdsX$conf,pch=20-(normX<=.5),col=2+6*(normX>.5))
tsne# install.packages("tsne")
library(tsne)
#?tsne
help(tsne::tsne))colors = rainbow(length(unique(iris$Species)))
names(colors) = unique(iris$Species)
ecb = function(x,y){ plot(x,t='n'); text(x,labels=iris$Species, col=colors[iris$Species]) }
tsne_iris = tsne(iris[,1:4], epoch_callback = ecb, perplexity=50)
## sigma summary: Min. : 0.565012665854053 |1st Qu. : 0.681985646004023 |Median : 0.713004330336136 |Mean : 0.716213420895748 |3rd Qu. : 0.74581655363904 |Max. : 0.874979764925049 |
## Epoch: Iteration #100 error is: 12.111253761122
## Epoch: Iteration #200 error is: 0.247122309410303
## Epoch: Iteration #300 error is: 0.227777755270182
## Epoch: Iteration #400 error is: 0.190501544065866
## Epoch: Iteration #500 error is: 0.189522085250119
## Epoch: Iteration #600 error is: 0.189521589496453
## Epoch: Iteration #700 error is: 0.189521588496729
## Epoch: Iteration #800 error is: 0.189521588496718
## Epoch: Iteration #900 error is: 0.189521588496718
## Epoch: Iteration #1000 error is: 0.189521588496718
Comparing with PCA:
# compare to PCA
pca_iris = princomp(iris[,1:4])$scores[,1:2]
plot(pca_iris, t='n')
text(pca_iris, labels=iris$Species,col=colors[iris$Species])
## End of Iris data example (from help(tsne::tsne))
Reading the data:
#install.packages("xgobi")
library(xgobi)
data(morsecodes)
# ?morsecodes
morsecodes.row
# computing the generalized Levenshtein (edit) distance between letters morse code
ad.mc <- adist(morsecodes.row[,2])
To be used during tsne::tsne: epoch_callback should be a callback function used after each epoch (an epoch here means a set number of iterations).
ecb.morse <- function(X,...){
pairs(X,
upper.panel=function(x,y,...){text(x,y,morsecodes.row[,1],...)},
lower.panel=function(x,y,...){text(x,y,morsecodes.row[,2],cex=2,...)},
col=nchar(morsecodes.row[,2])
)
}
tsne_morse <- tsne(ad.mc, k=3, initial_dims=6, epoch_callback = ecb.morse,
max_iter= 5000, epoch=500, perplexity=3)
## End of Working with Morse codes
Rtsne# install.packages("Rtsne")
library(Rtsne)
#?Rtsne
help(Rtsne::Rtsne))iris_unique <- unique(iris) # Remove duplicates
iris_matrix <- as.matrix(iris_unique[,1:4])
# Set a seed if you want reproducible results
set.seed(42)
tsne_out <- Rtsne(iris_matrix,pca=FALSE,perplexity=30,theta=0.0) # Run TSNE
# Show the objects in the 2D tsne representation
plot(tsne_out$Y,col=iris_unique$Species, asp=1)
# data.frame as input
tsne_out <- Rtsne(iris_unique,pca=FALSE, theta=0.0)
plot(tsne_out$Y,col=iris_unique$Species, asp=1)
# Using a dist object
set.seed(42)
tsne_out <- Rtsne(dist(normalize_input(iris_matrix)), theta=0.0)
plot(tsne_out$Y,col=iris_unique$Species, asp=1)
set.seed(42)
tsne_out <- Rtsne(as.matrix(dist(normalize_input(iris_matrix))),theta=0.0)
plot(tsne_out$Y,col=iris_unique$Species, asp=1)
# Supplying starting positions (example: continue from earlier embedding)
set.seed(42)
tsne_part1 <- Rtsne(iris_unique[,1:4], theta=0.0, pca=FALSE, max_iter=350)
tsne_part2 <- Rtsne(iris_unique[,1:4], theta=0.0, pca=FALSE, max_iter=650, Y_init=tsne_part1$Y)
plot(tsne_part2$Y,col=iris_unique$Species, asp=1)
# Fast PCA and multicore
tsne_out <- Rtsne(iris_matrix, theta=0.1, partial_pca = TRUE, initial_dims=3)
## Warning in (function (A, nv = 5, nu = nv, maxit = 1000, work = nv + 7, reorth =
## TRUE, : You're computing too large a percentage of total singular values, use a
## standard svd instead.
plot(tsne_out$Y,col=iris_unique$Species, asp=1)
tsne_out <- Rtsne(iris_matrix, theta=0.1, num_threads = 2)
plot(tsne_out$Y,col=iris_unique$Species, asp=1)
## End of Iris data example (from help(Rtsne::Rtsne))
### Reading the data
#install.packages("xgobi")
library(xgobi)
data(morsecodes)
# ?morsecodes
morsecodes.row
# computing the generalized Levenshtein (edit) distance between letters morse code
ad.mc <- adist(morsecodes.row[,2])
set.seed(42)
Rtsne_morse <- Rtsne(ad.mc, dims=3, initial_dims=6, max_iter= 5000, perplexity=3,theta=0.0)
pairs(Rtsne_morse$Y,
upper.panel=function(x,y,...){text(x,y,morsecodes.row[,1],...)},
lower.panel=function(x,y,...){text(x,y,morsecodes.row[,2],cex=2,...)},
col=nchar(morsecodes.row[,2])
)
## End of Working with Morse codes
Rtsne_X <- Rtsne(dX, dims=2,initial_dims=10, max_iter= 500, perplexity=5,theta=0.0)
plot(Rtsne_X$Y,pch=20-(normX<=.5),col=2+6*(normX>.5))
### ZIP numbers, from the book of Hastie et al.
#
# Data originally in
# https://web.stanford.edu/~hastie/ElemStatLearn/datasets/zip.train.gz
# https://web.stanford.edu/~hastie/ElemStatLearn/datasets/zip.test.gz
#
zip.train <- read.table("../../unsup/zip.train")
dim(zip.train)
## [1] 7291 257
n<-dim(zip.train)[1]
# PCA
zip.PC <- princomp(zip.train[,-1])
summary(zip.PC)
## Importance of components:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
## Standard deviation 4.6495483 3.2922882 2.81846757 2.59118002 2.43724515
## Proportion of Variance 0.1788442 0.0896704 0.06571727 0.05554546 0.04914189
## Cumulative Proportion 0.1788442 0.2685146 0.33423191 0.38977737 0.43891926
## Comp.6 Comp.7 Comp.8 Comp.9 Comp.10
## Standard deviation 2.15780432 1.98846183 1.92670509 1.76145366 1.71622656
## Proportion of Variance 0.03851923 0.03271056 0.03071029 0.02566823 0.02436703
## Cumulative Proportion 0.47743849 0.51014905 0.54085934 0.56652756 0.59089460
## Comp.11 Comp.12 Comp.13 Comp.14 Comp.15
## Standard deviation 1.62238456 1.56290817 1.43502301 1.33260441 1.30839562
## Proportion of Variance 0.02177514 0.02020786 0.01703614 0.01469115 0.01416223
## Cumulative Proportion 0.61266974 0.63287760 0.64991374 0.66460489 0.67876712
## Comp.16 Comp.17 Comp.18 Comp.19 Comp.20
## Standard deviation 1.25263540 1.21683945 1.18017523 1.13247191 1.09679104
## Proportion of Variance 0.01298084 0.01224955 0.01152249 0.01060983 0.00995179
## Cumulative Proportion 0.69174796 0.70399751 0.71552000 0.72612983 0.73608162
## Comp.21 Comp.22 Comp.23 Comp.24
## Standard deviation 1.087076832 1.050582782 1.009424404 0.969835114
## Proportion of Variance 0.009776286 0.009130908 0.008429485 0.007781248
## Cumulative Proportion 0.745857904 0.754988813 0.763418298 0.771199545
## Comp.25 Comp.26 Comp.27 Comp.28
## Standard deviation 0.933151758 0.91865935 0.874317092 0.869942021
## Proportion of Variance 0.007203739 0.00698172 0.006323993 0.006260861
## Cumulative Proportion 0.778403284 0.78538500 0.791708997 0.797969858
## Comp.29 Comp.30 Comp.31 Comp.32
## Standard deviation 0.862095171 0.843060044 0.822802351 0.811229242
## Proportion of Variance 0.006148425 0.005879907 0.005600728 0.005444282
## Cumulative Proportion 0.804118283 0.809998189 0.815598917 0.821043199
## Comp.33 Comp.34 Comp.35 Comp.36
## Standard deviation 0.793791052 0.763563552 0.755308302 0.746225453
## Proportion of Variance 0.005212737 0.004823295 0.004719565 0.004606738
## Cumulative Proportion 0.826255937 0.831079231 0.835798796 0.840405534
## Comp.37 Comp.38 Comp.39 Comp.40
## Standard deviation 0.725388549 0.706073499 0.700817218 0.686568965
## Proportion of Variance 0.004353062 0.004124329 0.004063151 0.003899615
## Cumulative Proportion 0.844758596 0.848882925 0.852946075 0.856845691
## Comp.41 Comp.42 Comp.43 Comp.44
## Standard deviation 0.679573296 0.659661475 0.656466442 0.63022145
## Proportion of Variance 0.003820551 0.003599943 0.003565156 0.00328579
## Cumulative Proportion 0.860666242 0.864266185 0.867831341 0.87111713
## Comp.45 Comp.46 Comp.47 Comp.48
## Standard deviation 0.623512333 0.617355043 0.615488003 0.599353752
## Proportion of Variance 0.003216204 0.003152996 0.003133954 0.002971802
## Cumulative Proportion 0.874333334 0.877486330 0.880620284 0.883592086
## Comp.49 Comp.50 Comp.51 Comp.52
## Standard deviation 0.588425081 0.574615837 0.563708385 0.554340433
## Proportion of Variance 0.002864414 0.002731547 0.002628829 0.002542181
## Cumulative Proportion 0.886456500 0.889188047 0.891816877 0.894359058
## Comp.53 Comp.54 Comp.55 Comp.56
## Standard deviation 0.540742829 0.533036462 0.524495131 0.521790019
## Proportion of Variance 0.002418995 0.002350538 0.002275812 0.002252397
## Cumulative Proportion 0.896778053 0.899128591 0.901404403 0.903656800
## Comp.57 Comp.58 Comp.59 Comp.60
## Standard deviation 0.514114765 0.504246928 0.499944390 0.498858499
## Proportion of Variance 0.002186621 0.002103488 0.002067744 0.002058772
## Cumulative Proportion 0.905843421 0.907946909 0.910014653 0.912073425
## Comp.61 Comp.62 Comp.63 Comp.64
## Standard deviation 0.497009823 0.471791249 0.464370075 0.457428901
## Proportion of Variance 0.002043541 0.001841421 0.001783947 0.001731014
## Cumulative Proportion 0.914116966 0.915958387 0.917742334 0.919473348
## Comp.65 Comp.66 Comp.67 Comp.68
## Standard deviation 0.451008563 0.444927818 0.435211916 0.433914468
## Proportion of Variance 0.001682763 0.001637693 0.001566949 0.001557621
## Cumulative Proportion 0.921156111 0.922793804 0.924360754 0.925918374
## Comp.69 Comp.70 Comp.71 Comp.72
## Standard deviation 0.426542737 0.420104990 0.41855344 0.411910055
## Proportion of Variance 0.001505146 0.001460055 0.00144929 0.001403648
## Cumulative Proportion 0.927423520 0.928883575 0.93033286 0.931736513
## Comp.73 Comp.74 Comp.75 Comp.76
## Standard deviation 0.408101058 0.40243569 0.393395741 0.392424457
## Proportion of Variance 0.001377809 0.00133982 0.001280303 0.001273989
## Cumulative Proportion 0.933114321 0.93445414 0.935734444 0.937008433
## Comp.77 Comp.78 Comp.79 Comp.80
## Standard deviation 0.388575186 0.380942221 0.379336903 0.376320500
## Proportion of Variance 0.001249118 0.001200526 0.001190429 0.001171573
## Cumulative Proportion 0.938257551 0.939458077 0.940648506 0.941820079
## Comp.81 Comp.82 Comp.83 Comp.84
## Standard deviation 0.366706190 0.36516614 0.363364117 0.35546584
## Proportion of Variance 0.001112474 0.00110315 0.001092289 0.00104532
## Cumulative Proportion 0.942932553 0.94403570 0.945127991 0.94617331
## Comp.85 Comp.86 Comp.87 Comp.88
## Standard deviation 0.353554314 0.349583357 0.3467216409 0.3408411904
## Proportion of Variance 0.001034108 0.001011009 0.0009945241 0.0009610757
## Cumulative Proportion 0.947207419 0.948218428 0.9492129517 0.9501740274
## Comp.89 Comp.90 Comp.91 Comp.92
## Standard deviation 0.3352180770 0.3303890619 0.3274037506 0.3255918342
## Proportion of Variance 0.0009296261 0.0009030353 0.0008867899 0.0008770017
## Cumulative Proportion 0.9511036534 0.9520066888 0.9528934787 0.9537704804
## Comp.93 Comp.94 Comp.95 Comp.96
## Standard deviation 0.3207395099 0.318901623 0.3157686676 0.311005599
## Proportion of Variance 0.0008510564 0.000841331 0.0008248814 0.000800184
## Cumulative Proportion 0.9546215368 0.955462868 0.9562877491 0.957087933
## Comp.97 Comp.98 Comp.99 Comp.100
## Standard deviation 0.3093284833 0.3051476438 0.3029402039 0.3019169018
## Proportion of Variance 0.0007915772 0.0007703241 0.0007592193 0.0007540989
## Cumulative Proportion 0.9578795103 0.9586498343 0.9594090537 0.9601631525
## Comp.101 Comp.102 Comp.103 Comp.104
## Standard deviation 0.2998397611 0.2983395884 0.2934904655 0.2925616856
## Proportion of Variance 0.0007437584 0.0007363346 0.0007125928 0.0007080898
## Cumulative Proportion 0.9609069109 0.9616432455 0.9623558383 0.9630639280
## Comp.105 Comp.106 Comp.107 Comp.108
## Standard deviation 0.2882626539 0.2856810814 0.2853403736 0.2822022085
## Proportion of Variance 0.0006874327 0.0006751751 0.0006735656 0.0006588313
## Cumulative Proportion 0.9637513607 0.9644265358 0.9651001014 0.9657589327
## Comp.109 Comp.110 Comp.111 Comp.112
## Standard deviation 0.278088157 0.2753151310 0.2730751779 0.269052050
## Proportion of Variance 0.000639762 0.0006270665 0.0006169044 0.000598861
## Cumulative Proportion 0.966398695 0.9670257611 0.9676426656 0.968241527
## Comp.113 Comp.114 Comp.115 Comp.116
## Standard deviation 0.2664143734 0.2649573137 0.2615239265 0.2578605677
## Proportion of Variance 0.0005871766 0.0005807714 0.0005658174 0.0005500768
## Cumulative Proportion 0.9688287032 0.9694094746 0.9699752920 0.9705253687
## Comp.117 Comp.118 Comp.119 Comp.120
## Standard deviation 0.2564735981 0.2550202435 0.2538425825 0.2499506389
## Proportion of Variance 0.0005441752 0.0005380254 0.0005330677 0.0005168469
## Cumulative Proportion 0.9710695439 0.9716075693 0.9721406370 0.9726574839
## Comp.121 Comp.122 Comp.123 Comp.124
## Standard deviation 0.2484174744 0.246958318 0.2436815201 0.2426743984
## Proportion of Variance 0.0005105258 0.000504546 0.0004912455 0.0004871933
## Cumulative Proportion 0.9731680098 0.973672556 0.9741638013 0.9746509946
## Comp.125 Comp.126 Comp.127 Comp.128
## Standard deviation 0.2399298952 0.2362080240 0.2346346051 0.2332635266
## Proportion of Variance 0.0004762359 0.0004615755 0.0004554467 0.0004501395
## Cumulative Proportion 0.9751272305 0.9755888060 0.9760442527 0.9764943922
## Comp.129 Comp.130 Comp.131 Comp.132
## Standard deviation 0.2323806377 0.2315278958 0.2296822186 0.227850157
## Proportion of Variance 0.0004467384 0.0004434657 0.0004364235 0.000429489
## Cumulative Proportion 0.9769411306 0.9773845963 0.9778210199 0.978250509
## Comp.133 Comp.134 Comp.135 Comp.136
## Standard deviation 0.2270644597 0.223573599 0.2213436431 0.2200798651
## Proportion of Variance 0.0004265321 0.000413518 0.0004053102 0.0004006951
## Cumulative Proportion 0.9786770411 0.979090559 0.9794958693 0.9798965644
## Comp.137 Comp.138 Comp.139 Comp.140
## Standard deviation 0.2184111886 0.2156784711 0.2156281609 0.2137590057
## Proportion of Variance 0.0003946419 0.0003848283 0.0003846488 0.0003780091
## Cumulative Proportion 0.9802912063 0.9806760347 0.9810606835 0.9814386926
## Comp.141 Comp.142 Comp.143 Comp.144
## Standard deviation 0.2113542743 0.2099612191 0.2085401869 0.2058398204
## Proportion of Variance 0.0003695519 0.0003646965 0.0003597766 0.0003505195
## Cumulative Proportion 0.9818082445 0.9821729410 0.9825327176 0.9828832372
## Comp.145 Comp.146 Comp.147 Comp.148
## Standard deviation 0.2055566514 0.2039274234 0.2021139961 0.2009709982
## Proportion of Variance 0.0003495558 0.0003440366 0.0003379451 0.0003341336
## Cumulative Proportion 0.9832327930 0.9835768296 0.9839147747 0.9842489084
## Comp.149 Comp.150 Comp.151 Comp.152
## Standard deviation 0.1979423760 0.1972265229 0.1956801773 0.1948544432
## Proportion of Variance 0.0003241388 0.0003217985 0.0003167722 0.0003141044
## Cumulative Proportion 0.9845730472 0.9848948457 0.9852116179 0.9855257223
## Comp.153 Comp.154 Comp.155 Comp.156
## Standard deviation 0.1933286001 0.1918718766 0.191345358 0.1884509552
## Proportion of Variance 0.0003092044 0.0003045623 0.000302893 0.0002937989
## Cumulative Proportion 0.9858349267 0.9861394890 0.986442382 0.9867361809
## Comp.157 Comp.158 Comp.159 Comp.160
## Standard deviation 0.1879563966 0.1860151655 0.1850280751 0.1828143725
## Proportion of Variance 0.0002922588 0.0002862531 0.0002832231 0.0002764866
## Cumulative Proportion 0.9870284397 0.9873146928 0.9875979159 0.9878744025
## Comp.161 Comp.162 Comp.163 Comp.164
## Standard deviation 0.1796703576 0.1784751353 0.1777565780 0.176762832
## Proportion of Variance 0.0002670584 0.0002635171 0.0002613995 0.000258485
## Cumulative Proportion 0.9881414609 0.9884049781 0.9886663776 0.988924863
## Comp.165 Comp.166 Comp.167 Comp.168
## Standard deviation 0.1752517566 0.1748036930 0.1735285771 0.1699930232
## Proportion of Variance 0.0002540845 0.0002527869 0.0002491125 0.0002390648
## Cumulative Proportion 0.9891789471 0.9894317340 0.9896808465 0.9899199113
## Comp.169 Comp.170 Comp.171 Comp.172
## Standard deviation 0.1690054885 0.1678675354 0.1668010095 0.1659935756
## Proportion of Variance 0.0002362953 0.0002331239 0.0002301711 0.0002279481
## Cumulative Proportion 0.9901562065 0.9903893305 0.9906195016 0.9908474497
## Comp.173 Comp.174 Comp.175 Comp.176
## Standard deviation 0.1624465998 0.1618570066 0.1616453113 0.1598571249
## Proportion of Variance 0.0002183105 0.0002167287 0.0002161621 0.0002114061
## Cumulative Proportion 0.9910657602 0.9912824889 0.9914986510 0.9917100571
## Comp.177 Comp.178 Comp.179 Comp.180
## Standard deviation 0.1588904153 0.1584804176 0.1571357326 0.156710358
## Proportion of Variance 0.0002088569 0.0002077804 0.0002042694 0.000203165
## Cumulative Proportion 0.9919189140 0.9921266944 0.9923309638 0.992534129
## Comp.181 Comp.182 Comp.183 Comp.184
## Standard deviation 0.1557837523 0.1529140015 0.1514692018 0.1506787933
## Proportion of Variance 0.0002007695 0.0001934407 0.0001898026 0.0001878269
## Cumulative Proportion 0.9927348983 0.9929283391 0.9931181416 0.9933059685
## Comp.185 Comp.186 Comp.187 Comp.188
## Standard deviation 0.149345681 0.1489673620 0.1474188808 0.1455682352
## Proportion of Variance 0.000184518 0.0001835844 0.0001797876 0.0001753019
## Cumulative Proportion 0.993490487 0.9936740709 0.9938538584 0.9940291603
## Comp.189 Comp.190 Comp.191 Comp.192
## Standard deviation 0.1441202829 0.1437279370 0.1422816102 0.1421520351
## Proportion of Variance 0.0001718318 0.0001708975 0.0001674754 0.0001671705
## Cumulative Proportion 0.9942009922 0.9943718897 0.9945393651 0.9947065356
## Comp.193 Comp.194 Comp.195 Comp.196
## Standard deviation 0.1406525171 0.1398266049 0.1386154472 0.138335706
## Proportion of Variance 0.0001636622 0.0001617458 0.0001589559 0.000158315
## Cumulative Proportion 0.9948701978 0.9950319436 0.9951908995 0.995349215
## Comp.197 Comp.198 Comp.199 Comp.200
## Standard deviation 0.1367118608 0.1341011860 0.1328238552 0.1323588874
## Proportion of Variance 0.0001546201 0.0001487711 0.0001459505 0.0001449305
## Cumulative Proportion 0.9955038346 0.9956526057 0.9957985562 0.9959434866
## Comp.201 Comp.202 Comp.203 Comp.204
## Standard deviation 0.1307267840 0.1295269202 0.1285403766 0.1268303087
## Proportion of Variance 0.0001413782 0.0001387949 0.0001366887 0.0001330759
## Cumulative Proportion 0.9960848649 0.9962236598 0.9963603485 0.9964934244
## Comp.205 Comp.206 Comp.207 Comp.208
## Standard deviation 0.1257365197 0.1250695378 0.1236937189 0.1223140039
## Proportion of Variance 0.0001307905 0.0001294066 0.0001265752 0.0001237673
## Cumulative Proportion 0.9966242149 0.9967536216 0.9968801968 0.9970039641
## Comp.209 Comp.210 Comp.211 Comp.212
## Standard deviation 0.1208773761 0.1198655251 0.1188283542 0.1175311567
## Proportion of Variance 0.0001208769 0.0001188617 0.0001168136 0.0001142772
## Cumulative Proportion 0.9971248410 0.9972437027 0.9973605164 0.9974747935
## Comp.213 Comp.214 Comp.215 Comp.216
## Standard deviation 0.1169432881 0.116019769 0.1151238319 0.1132669299
## Proportion of Variance 0.0001131368 0.000111357 0.0001096438 0.0001061353
## Cumulative Proportion 0.9975879304 0.997699287 0.9978089311 0.9979150664
## Comp.217 Comp.218 Comp.219 Comp.220
## Standard deviation 0.1114117214 0.1099639059 1.076139e-01 1.064101e-01
## Proportion of Variance 0.0001026869 0.0001000354 9.580553e-05 9.367398e-05
## Cumulative Proportion 0.9980177533 0.9981177887 9.982136e-01 9.983073e-01
## Comp.221 Comp.222 Comp.223 Comp.224
## Standard deviation 1.043082e-01 1.034553e-01 1.015226e-01 9.955675e-02
## Proportion of Variance 9.000999e-05 8.854393e-05 8.526654e-05 8.199641e-05
## Cumulative Proportion 9.983973e-01 9.984858e-01 9.985711e-01 9.986531e-01
## Comp.225 Comp.226 Comp.227 Comp.228
## Standard deviation 9.902450e-02 9.691754e-02 9.460932e-02 9.236487e-02
## Proportion of Variance 8.112201e-05 7.770665e-05 7.404936e-05 7.057764e-05
## Cumulative Proportion 9.987342e-01 9.988119e-01 9.988860e-01 9.989565e-01
## Comp.229 Comp.230 Comp.231 Comp.232
## Standard deviation 9.070851e-02 9.045117e-02 8.795739e-02 8.660161e-02
## Proportion of Variance 6.806902e-05 6.768334e-05 6.400267e-05 6.204479e-05
## Cumulative Proportion 9.990246e-01 9.990923e-01 9.991563e-01 9.992183e-01
## Comp.233 Comp.234 Comp.235 Comp.236
## Standard deviation 8.366343e-02 8.204772e-02 8.000195e-02 0.0787407937
## Proportion of Variance 5.790616e-05 5.569119e-05 5.294861e-05 0.0000512924
## Cumulative Proportion 9.992762e-01 9.993319e-01 9.993849e-01 0.9994361789
## Comp.237 Comp.238 Comp.239 Comp.240
## Standard deviation 7.732095e-02 7.440405e-02 0.0736994472 0.0719823841
## Proportion of Variance 4.945928e-05 4.579801e-05 0.0000449347 0.0000428653
## Cumulative Proportion 9.994856e-01 9.995314e-01 0.9995763709 0.9996192362
## Comp.241 Comp.242 Comp.243 Comp.244
## Standard deviation 7.085476e-02 6.749787e-02 6.628047e-02 6.571951e-02
## Proportion of Variance 4.153283e-05 3.769065e-05 3.634332e-05 3.573074e-05
## Cumulative Proportion 9.996608e-01 9.996985e-01 9.997348e-01 9.997705e-01
## Comp.245 Comp.246 Comp.247 Comp.248
## Standard deviation 6.434213e-02 6.176975e-02 6.030256e-02 5.330468e-02
## Proportion of Variance 3.424871e-05 3.156495e-05 3.008326e-05 2.350629e-05
## Cumulative Proportion 9.998048e-01 9.998363e-01 9.998664e-01 9.998899e-01
## Comp.249 Comp.250 Comp.251 Comp.252
## Standard deviation 5.266582e-02 0.047510753 4.609800e-02 4.250282e-02
## Proportion of Variance 2.294622e-05 0.000018674 1.757995e-05 1.494476e-05
## Cumulative Proportion 9.999129e-01 0.999931557 9.999491e-01 9.999641e-01
## Comp.253 Comp.254 Comp.255 Comp.256
## Standard deviation 3.888908e-02 3.732123e-02 2.874160e-02 2.470601e-02
## Proportion of Variance 1.251148e-05 1.152299e-05 6.834004e-06 5.049620e-06
## Cumulative Proportion 9.999766e-01 9.999881e-01 9.999950e-01 1.000000e+00
plot(zip.PC$scores[,1:2],pch=c(15,17,19)[(zip.train[,1]%%3)+1],cex=.75,col=zip.train[,1]+1)
legend("bottomright",legend=0:9,pch=c(15,17,19)[((0:9)%%3)+1],cex=.75,col=(0:9)+1)
plot(zip.PC$scores[,c(1,3)],pch=c(15,17,19)[(zip.train[,1]%%3)+1],cex=.75,col=zip.train[,1]+1)
legend("bottomright",legend=0:9,pch=c(15,17,19)[((0:9)%%3)+1],cex=.75,col=(0:9)+1)
pairs(zip.PC$scores[,1:4], pch=c(15,17,19)[(zip.train[,1]%%3)+1],cex=.75,col=zip.train[,1]+1)
# t-SNE
zip.Rtsne <- Rtsne(zip.train[,-1], dims=3, initial_dims=100,
max_iter= 1000, perplexity=50,theta=0.5)
plot(zip.Rtsne$Y[,1:2],pch=c(15,17,19)[(zip.train[,1]%%3)+1],cex=.75,col=zip.train[,1]+1)
legend("bottomright",legend=0:9,pch=c(15,17,19)[((0:9)%%3)+1],cex=.75,col=(0:9)+1)
plot(zip.Rtsne$Y[,c(1,3)],pch=c(15,17,19)[(zip.train[,1]%%3)+1],cex=.75,col=zip.train[,1]+1)
legend("bottomright",legend=0:9,pch=c(15,17,19)[((0:9)%%3)+1],cex=.75,col=(0:9)+1)
pairs(zip.Rtsne$Y[,1:3], pch=c(15,17,19)[(zip.train[,1]%%3)+1],cex=.75,col=zip.train[,1]+1)